/*
 * Copyright (C) 2016 The Android Open Source Project
 *  Created by  Ant  2016/8/26  15:43
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ant.view.cn.views;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import com.ant.view.cn.utils.AntLog;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by baichuan on 2016/8/26.
 */
public class View001 extends View{
    private String TAG = "";
    private int mwidth = 0, mheight = 0,mheight2=0;
    Paint paint1=new Paint();
    Paint paint2=new Paint();


    public View001(Context context) {
        super(context);
        init();
    }

    public View001(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public View001(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }


    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        init();
    }

    public void init() {
        TAG = this.getClass().getSimpleName();
        AntLog.i(TAG, "init ant");

        final Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                if (mheight > getHeight())
                    mheight=-100;
                mheight += 5;
                postInvalidate();
                AntLog.i(TAG, "width=" + mwidth + ", height=" + mheight);

            }
        }, 0, 100);

        final Timer timer2 =new Timer();
        timer2.schedule(new TimerTask() {
            @Override
            public void run() {
                if (mheight2 > getHeight()-200) {
                    mheight2 = -100;
                }
                mheight2 += 2;
                postInvalidate();
                AntLog.i(TAG, "width=" + mwidth + ", height=" + mheight);

            }
        }, 0, 100);

        paint1.setColor(Color.RED);
        paint2.setColor(Color.BLUE);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawRect(0, 0, 400, mheight, paint1);
        canvas.drawRect(0, 0, 200, mheight2, paint2);

    }


}
